using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class DamageBlock{
	public static List<string> ValidDamageTypes = new List<string>
	{
		"Physical", "Non-Lethal", "Acid", "Cold", "Electricity", "Fire", "Sonic"
	};
	
	public string damageType = "Physical";
	public int dieCount = 0;
	public int dieType = 6;
	
	public DamageBlock(string json = null)
	{
		if(json != null)
		{
			Dictionary<string,string> data = MiniJSON.Json.Deserialize(json) as Dictionary<string,string>;
			
			damageType = data["damageType"];
			dieCount = int.Parse(data["dieCount"]);
			dieType = int.Parse(data["dieType"]);
		}
	}
	
	public int Roll()
	{
		return Random.Range(dieCount, dieType*dieCount + 1);
	}
	
	public string ToJSON()
	{
		Dictionary<string,string> data = new Dictionary<string, string>();
		data.Add("damageType", damageType);
		data.Add("dieCount", dieCount.ToString());
		data.Add("dieType", dieType.ToString());
		
		return MiniJSON.Json.Serialize(data);
	}
}
